package com.example.javabasic.shejimoshi.beiwanglu.demo1;
//备忘录模式
public class Test {
    public static void main(String[] args) {
        //发起人
        Originator originator = new Originator();
        //管理者
        Caretaker caretaker = new Caretaker();
        //发起人状态一
        originator.setState("状态一");
        System.out.println("初始状态为:"+originator.getState());
        //保存状态
        caretaker.setMemento(new Memento(originator.getState()));
        //发起人变更状态为  状态二
        originator.setState("状态二");
        System.out.println("新的状态为:"+originator.getState());
        //开始恢复状态
        originator.restoreMemento(caretaker.getMemento());
        System.out.println("恢复状态为:"+originator.getState());
    }
}
